<?php
namespace Admin\Controller;

class StoreDotController extends BaseController
{

    public function index()
    {

        $storeDotModel = M('b2c_store_dot');
        $storeDotMsg = $storeDotModel->where(['local_id' => session('userInfo')['local_id']])->select();
        $local_name = M('webpos_local_store')->field('local_name')->where(['local_id' => session('userInfo')['local_id']])->find();

        $this->assign(['storeDotMsg' => $storeDotMsg, 'local_name' => $local_name]);
        $this->display();
    }

    public function add(){

        if ($_POST) {

            $name= I('name' , '', htmlentities());
            $tihuo_time= I('tihuo_time' , '', htmlentities());
            $tel= I('tel' , '', htmlentities());
            $addr= I('addr' , '', htmlentities());

            $storeDotModel = M('b2c_store_dot');

            $data = [
                'local_id' => session('userInfo')['local_id'],
                'store_dot_name' => $name,
                'tihuo_time' => $tihuo_time,
                'tel' => $tel,
                'addr' => $addr,
            ];
            $storeDotModel->add($data);
            $this->success('添加成功', '/admin/storeDot/index');
            exit;
        }
        $this->display();
    }

    public function edit(){

        $dot_id = I('dot_id', '', htmlentities());
        if (empty($dot_id)) {
            $this->error('错误');
        }
        $storeDotModel = M('b2c_store_dot');
        $storeDotMsg = $storeDotModel->where(['dot_id' => $dot_id, 'local_id' => session('userInfo')['local_id']])->find();
        if (empty($storeDotMsg)) {
            $this->error('错误');
        }

        if ($_POST) {
            $name= I('name' , '', htmlentities());
            $tihuo_time= I('tihuo_time' , '', htmlentities());
            $tel= I('tel' , '', htmlentities());
            $addr= I('addr' , '', htmlentities());

            $storeDotModel = M('b2c_store_dot');

            $data = [
                'local_id' => session('userInfo')['local_id'],
                'store_dot_name' => $name,
                'tihuo_time' => $tihuo_time,
                'tel' => $tel,
                'addr' => $addr,
            ];
            $storeDotModel->where(['dot_id' => $dot_id])->save($data);
            $this->success('修改成功', '/admin/storeDot/index');
            exit;
        }

        $this->assign(['storeDotMsg' => $storeDotMsg]);
        $this->display();
    }

    public function delete(){
        $dot_id = I('dot_id', '', htmlentities());
        if (empty($dot_id)) {
            $this->error('错误');
        }
        $storeDotModel = M('b2c_store_dot');
        $storeDotModel->delete($dot_id);
        $this->success('已删除', '/admin/storeDot/index');
    }

}